package com.gu.antiSpamCall.config;

import com.gu.antiSpamCall.interceptor.AdminAuthenticationInterceptor;
import com.gu.antiSpamCall.interceptor.UserAuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminAuthenticationInterceptor())
                .addPathPatterns("/admin/**")
                .addPathPatterns("/simulator/**")
                .addPathPatterns("/model/**");

        registry.addInterceptor(userAuthInterceptor())
                .addPathPatterns("/user/**");
    }

    @Bean
    public AdminAuthenticationInterceptor adminAuthenticationInterceptor() {
        return new AdminAuthenticationInterceptor();
    }

    @Bean
    public UserAuthInterceptor userAuthInterceptor() {
        return new UserAuthInterceptor();
    }
}
